package com.carrent.demo.Controller;

import com.carrent.demo.Domain.UserContract;
import com.carrent.demo.Service.UserContractService;
import com.carrent.demo.Utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/userContract")
public class

UserContractController {
    @Autowired
    UserContractService UsercontractService;

    @GetMapping("/page")
    public R getPage(Integer page, Integer pageSize, String name)
    {
        final List<UserContract> page1 = UsercontractService.getPage((page - 1) * pageSize, pageSize, name);
        final Integer count = UsercontractService.getCount(name);
        return  R.success(page1,count);
    }

    @PutMapping
    public  R editUserContract(@RequestBody UserContract userContract)
    {
        UsercontractService.editUserContract(userContract);
        return  R.success(1);
    }
    @PostMapping("/status/{status}")
    public  R editReturn(@PathVariable Integer status,@RequestParam(value = "ids") List<Integer> ids)
    {
        for (Integer i : ids)
        {
            UsercontractService.editReturn(i,status);
        }
        return  R.success("");
    }


}